// pages/my/visitor/editInfo/editInfo.js
const app = getApp()
var base_url = app.globalData.url
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({

      success: function (res) {
        let clientHeight = res.windowHeight;
        let clientWidth = res.windowWidth;
        let ratio = 750 / clientWidth;
        let height = clientHeight * ratio;
        that.setData({
          height: clientHeight
        });
      }
    });
    wx.getStorage({
      key: 'student_id',
      success: function (resl) {
        that.setData({
          student_id:resl.data
        })
      },

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  setNameValue: function (res) {
    var that = this;
    that.setData({
      nameValue: res.detail.value
    })
  },
  setStudentCodeValue: function (res) {
    var that = this;
    that.setData({
      studentCodeValue: res.detail.value
    })
  },
  confirm:function(){
    var that = this;
    var student_id =
      wx.request({
        url: base_url+'/setStudentInfo/',
        method: 'POST',
        data: {
          nameValue: that.data.nameValue,
          studentCodeValue: that.data.studentCodeValue,
          student_id: that.data.student_id
        },
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        success: function (resl) {
          console.log(resl)
          if (resl.data['flag'] == true) {
            that.setData({
              ifName: true
            })
            wx.navigateTo({
              url: '../mine/mine',
              success: function (res) {
                console.log(res)
              },
              fail: function () {
              }
            })
          }
        }
      })
  }
})